package com.example.tt;

import java.util.Observable;
import java.util.Observer;
import java.util.concurrent.Callable;
import java.util.function.Supplier;

import static java.lang.Thread.sleep;

/**
 * @Author: wws
 * describe:
 */
public class ObServer implements Observer, Callable<String> {


    private String message;
    Observable observable;

    @Override
    public void update(Observable o, Object arg) {
        System.out.println("OB update+++++++++++++++++"+arg);
        this.observable = o;
        this.message = (String) arg;

        synchronized (this){
            notify();
        }

    }

    /**
     * Computes a result, or throws an exception if unable to do so.
     *
     * @return computed result
     * @throws Exception if unable to compute a result
     */
    @Override
    public String call() throws Exception {

            System.out.println("监听者启动");
            for (; ; ) {
                System.out.println( "OB执行一次");
                synchronized (this){
                   wait();
                }
                if (message==null){
                    continue;
                }
                if (message.equals("11")) {
                    System.out.println("OB收到了");
                    return "我他妈收到了";
                }
            }



    }



}
